package com.guli.product.controller;

import com.guli.common.response.Result;
import com.guli.model.product.CategoryEntity;
import com.guli.model.product.dto.CategoryDTO;
import com.guli.product.mapper.CategoryMapper;
import com.guli.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product/category")
public class CategotyController {
    @Autowired
    CategoryService categoryService;

    @GetMapping("findTreeCategoryDTO")
    public List<CategoryDTO> findTreeCategoryDTO(){
        return categoryService.findTreeCategoryDTO();
    }

    @GetMapping("listTreeCategoryDTO")
    public List<CategoryDTO> listTreeCategoryDTO(){
        return categoryService.findTreeCategoryDTO();
    }

    //添加 修改 listTreeCategoryDTO
    @PostMapping("/save")
    public Result save(@RequestBody CategoryEntity categoryEntity){
        return categoryService.save(categoryEntity);
    }

    //id 查询
    @GetMapping("seleteByid")
    public CategoryEntity seleteByid(@RequestParam("catid") Long catid){
        return categoryService.seleteByid(catid);
    }

    //删除
    @GetMapping("deleteByid")
    public Result deleteByid(@RequestParam("catid") Long catid){
        return   categoryService.deleteByid(catid);
    }

}
